/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nurdrobotics;

import edu.wpi.first.wpilibj.Joystick;

/**
 *
 * @author hpadmin
 */
public class Button {

    private boolean pressed = false;
    private boolean lastPressed = false;
    Joystick stick;
    int port;

    public Button(Joystick stick, int port) {
        this.stick = stick;
        this.port = port;

    }

    public boolean isPressed() {
        return pressed;
    }

    public boolean RisingEdge() {
        // determine whether the button is currently pressed
        pressed = stick.getRawButton(port);


        // if the button is currently pressed, and it wasn't pressed last time
        // then set the return value to reflect this is a rising edge
        boolean returnValue = (pressed && (lastPressed == false));


        // update the last pressed value to the currently pressed value
        lastPressed = pressed;

        // return the result of whether or not this was a rising edge
        return returnValue;
    }

    public boolean FallingEdge() {
        // determine whether the button is currently pressed
        pressed = stick.getRawButton(port);


        // if the button is not currently pressed, and it was pressed last time
        // then set the return value to reflect this is a falling edge
        boolean returnValue = (lastPressed && (pressed == false));


        // update the last pressed value to the currently pressed value
        lastPressed = pressed;

        // return the result of whether or not this was a falling edge
        return returnValue;
    }
}
